//
//  HJBaseNavController.swift
//  HJWeiBo
//
//  Created by 夏航军 on 16/9/22.
//  Copyright © 2016年 夏航军. All rights reserved.
//

import UIKit

class HJBaseNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //重写Push方法
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
       
        //因为我们在调用push的时候就会闯进来目标控制器,而我们重写了方法,系统就会调用次方法,我们就能拿到目标控制器,此处的viewController就是目标控制器
        //print(childViewControllers.count)
        
        //UINavigationController(rootViewController:) 内部执行了push 
        //我们在用storyBoard的时候就会有一个导航控制器和一个根控制器,系统运行时会自动的push到根控制器
        let count = childViewControllers.count
        if count > 0 {
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(back))
        
        viewController.hidesBottomBarWhenPushed = true
        }
         super.pushViewController(viewController, animated: animated)
        
        //print(childViewControllers.count)
    }
    
    @objc private func back() {
        
        self.popViewController(animated: true)
        
    }

}
